﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Text;
using Chenxin.Lib.Utility;

public partial class MasterPage : System.Web.UI.MasterPage
{
    public string strUserName = "";
    public static Chenxin.Lib.Passport.BLL.Cache_UserInfo userInfo;
    public string strBusinessUrl = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        strBusinessUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["WebRoot.Business"] + "/page/Contract_ApplyInfo/ContractQuickSearch.aspx";
        if (!IsPostBack)
        {
            GetUserInfo();

            //王玮2010-4-7 添加
            //得到所需检查权限的HL,遍历其后显示.
            SetAllHyperLink(leftmenu.Controls);

            //SetThePublishUrl();
        }
    }

    /// <summary>
    /// 获取UserInfo
    /// </summary>
    protected void GetUserInfo()
    {
        //用户Id
        string strUserId;
        //从Cookies取得用户Id
        string strRequestKey = Request.Cookies["requestkey"].Value;
        string strCachedKey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_REQUEST, strRequestKey);
        Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
        strUserId = cs.GetString(strCachedKey);
        if (!cs.Hit)
            Response.Redirect("loginex.aspx", true);

        //用户基本信息业务类
        Chenxin.Lib.Passport.BLL.Cache_UserInfo bllCacheUserInfo = new Chenxin.Lib.Passport.BLL.Cache_UserInfo(new Guid(strUserId));
        //得到当前用户信息
        userInfo = bllCacheUserInfo.GetCurrentUserInfo();
        if (userInfo != null) strUserName = userInfo.UserName + "【"+userInfo.DepartName + "】";

    }

    /// <summary>
    /// 根据编号（URL）来判断此用户相应的权限显示于UI上
    /// 王玮 2010-4-7 添加
    /// </summary>
    /// <param name="hlk"></param>
    protected void SetAllHyperLink(ControlCollection frmChildren)
    {
        HyperLink hlTemp;

        foreach (object curObj in frmChildren)
        {
            if (curObj.GetType() == typeof(System.Web.UI.WebControls.HyperLink))
            {
                hlTemp = (HyperLink)curObj;
                if (hlTemp.NavigateUrl == "#")
                    hlTemp.Visible = false;
                else
                {
                    string[] hlurls = hlTemp.NavigateUrl.Split(new Char[] { '/' });
                    string hlurl = hlurls[hlurls.Length - 1];

                    if (!userInfo.ContainsPermit((hlurl.Split('?')[0]).ToLower()))
                    {
                        hlTemp.Visible = false;
                    }
                }
            }
        }
    }
}
